package com.acwing.partition4;

import java.io.*;
import java.util.Deque;
import java.util.LinkedList;

/**
 * @author `RKC`
 * @date 2022/1/12 15:30
 */
public class AC340通信线路 {

    private static final int N = 1010, M = 10010 * 2, INF = 0x3f3f3f3f;
    private static int n = 0, m = 0, k = 0, index = 0;
    private static int[] head = new int[N], element = new int[M], next = new int[M], weight = new int[M];

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        String[] s = reader.readLine().split("\\s+");
        n = Integer.parseInt(s[0]);
        m = Integer.parseInt(s[1]);
        k = Integer.parseInt(s[2]);
        for (int i = 0; i < N; i++) head[i] = -1;
        int max = -INF;
        for (int i = 0; i < m; i++) {
            s = reader.readLine().split("\\s+");
            int u = Integer.parseInt(s[0]), v = Integer.parseInt(s[1]), w = Integer.parseInt(s[2]);
            max = Math.max(max, w);
            createEdge(u, v, w);
            createEdge(v, u, w);
        }
        writer.write(resolve(max) + "\n");
        writer.flush();
    }

    private static int resolve(int max) {
        //二分枚举答案target，target以上的路径免费升级，对k的贡献加1，以下的贡献为0
        int left = 0, right = max;
        while (left < right) {
            int mid = (left + right) >>> 1;
            //check当前免费升级的线路，如果能免费升级的太多超过了k条，就提高left；如果太少了远不到k条，说明达到要求的线路太少，需要降低要求，
            //因为要求最小，所以小于等于都降低right
            if (check(mid) <= k) right = mid;
            else left = mid + 1;
        }
        return left == max ? -1 : left;
    }

    private static int check(int mid) {
        Deque<Integer> deque = new LinkedList<>();
        int[] dist = new int[n + 1];
        boolean[] visited = new boolean[n + 1];
        for (int i = 0; i <= n; i++) dist[i] = INF;
        dist[1] = 0;
        deque.addLast(1);
        while (!deque.isEmpty()) {
            int u = deque.pollFirst();
            if (visited[u]) continue;
            visited[u] = true;
            for (int i = head[u]; i != -1; i = next[i]) {
                int v = element[i], dis = weight[i] > mid ? 1 : 0;
                if (dist[v] > dist[u] + dis) {
                    dist[v] = dist[u] + dis;
                    if (dis == 1) deque.addLast(v);
                    else deque.addFirst(v);
                }
            }
        }
        return dist[n];
    }

    private static void createEdge(int u, int v, int w) {
        element[index] = v;
        next[index] = head[u];
        head[u] = index;
        weight[index++] = w;
    }
}
